<template>
    <el-dialog
        :before-close="resetForm"
        :close-on-click-modal="false"
        :visible.sync="visible"
        append-to-body
        title="编辑公告信息"
        width="600px"
    >
        <div class="edit_page_div">
            <el-form ref="form" :model="form" :rules="rules" :show-message="false" label-width="100px">
                <el-form-item label="公告编号" prop="noticeCode">
                    <el-input v-model="form.noticeCode" style="width: 400px;" placeholder="系统生成" disabled></el-input>
                </el-form-item>
                <el-form-item label="公告标题" prop="noticeTitle">
                    <el-input v-model="form.noticeTitle" style="width: 400px;"></el-input>
                </el-form-item>
                <el-form-item label="公告内容" prop="noticeContent">
                    <el-input v-model="form.noticeContent" rows="5" style="width: 400px;" type="textarea"></el-input>
                </el-form-item>
				<el-form-item label="开始日期" prop="beginDate">
					<el-date-picker v-model="form.beginDate" style="width: 400px;" type="date" value-format="yyyy-MM-dd"></el-date-picker>
				</el-form-item>
				<el-form-item label="结束日期" prop="endDate">
					<el-date-picker v-model="form.endDate" style="width: 400px;" type="date" value-format="yyyy-MM-dd"></el-date-picker>
				</el-form-item>
                <el-form-item label="拉收人员" prop="receiveUser">
                    <select-option select-width="400px" v-model="form.receiveUser" :list="receiveUserLIst"></select-option>
                </el-form-item>
            </el-form>
            <div class="edit_button">
                <el-button v-loading.fullscreen.lock="loading" type="primary" @click="submit">保 存</el-button>
                <el-button type="primary" @click="resetForm">取 消</el-button>
            </div>
        </div>
    </el-dialog>
</template>

<script>
import SelectOption from "@/components/select/selectOption.vue";

export default {
    name: "noticeEdit",
    components: {SelectOption},
    props: {
        visible: Boolean,
        id: String,
    },
    data() {
        return {
            loading: false,
            
            form: {
                noticeTitle: '',
                noticeContent: '',
				beginDate: '',
				endDate: '',
                receiveUser: '',
            },
            rules: {
                noticeTitle: [{required: true, message: '不能为空', trigger: 'change'}],
                noticeContent: [{required: true, message: '不能为空', trigger: 'change'}],
				beginDate: [{required: true, message: '不能为空', trigger: 'change'}],
				endDate: [{required: true, message: '不能为空', trigger: 'change'}],
            },

            receiveUserLIst: [],
        }
    },
    watch: {
        visible(newVal) {
            if (newVal) {
                this.receiveUserLIst = this.$common.getDicList("receiveUser");
                if (this.id) {
                    this.getData();
                }
            }
        }
    },
    methods: {
        getData() {
            this.loading = true;
            this.$axios.get("/CHILD_SYSTEM/systemNotice/getOneEntity/" + this.id).then(res => {
                this.form = res.data;
                this.form.newsType = 1;
            }).finally(() => {
                this.loading = false;
            })
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    this.$axios.post("/CHILD_SYSTEM/systemNotice/" + (this.id ? "update" : "insert"), this.form).then(() => {
                        this.resetForm();
                        this.$message.success(res.message);
                    }).finally(() => {
                        this.loading = false;
                    })
                } else {
                    this.$message.error('表单填写有误');
                    return false;
                }
            });
        },
        resetForm() {
            this.$refs.form.resetFields();
            this.form = this.$options.data().form;
            this.$emit('update:visible', false);
            this.$emit('refreshList');
        },
    }
}
</script>

<style lang="scss">

</style>